package controllers.interfaces.media;

import java.io.File;
import java.util.Map;

import aws.AWSUtil;
import controllers.BaseController;
import net.sf.json.JSONObject;
import play.Logger;
import producers.IMediaProducer;
import producers.MediaProducer;
import utils.Constant;
/**
 * 语音文件上传
 * @author jinchaoyang
 */
public class Medias extends BaseController {
    
    public static void upload(){
        String sid = Constant.UCPAAS_SID;
        String token = Constant.UCPAAS_TOKEN;
        String appId = params.get("appId");
        String nickName = params.get("nickName");
        appId=Constant.UCPAAS_APPID; //测试使用,正式环境删除
        String fileName = params.get("fileName");
        IMediaProducer producer = new MediaProducer(sid, token, appId);
        //目录结构 uobject/tenantId(域名)/ucpaas/appId/ivr
        nickName="xiaona.nickName.com";
        String dir= nickName+"/ucpaas/"+appId+"/ivr/";
        File f = AWSUtil.fetchFile(Constant.AWS_BUCKET_NAME,dir,fileName);
        Map<String,String> result = producer.upload(sid, token,appId, f);
        JSONObject obj = JSONObject.fromObject(result);
        Logger.info("[%s]: sid<%s>, token<%s>, appId<%s>, fileName<%s>, result<%s>","upload",sid,token,appId,fileName,result);
        renderJSON(obj);
    }
}
